<?php

// 应用公共文件

/**
 * 加密方式
 * @param string $pw 要加密的字符串
 * @return string  $authcode   随机字符串
 */
function pw($pw,$authcode=''){
    if(empty($authcode)){
        $authcode=config("database.authcode");
    }
    $result=md5(md5($authcode.$pw));
    return $result;
}



/**
 * 调用淘宝地址库
 * */
function ip_taobao($ip){
    $urlTaobao = 'http://ip.taobao.com/service/getIpInfo.php?ip='.$ip;
    $json = file_get_contents($urlTaobao);
    $jsonDecode = json_decode($json);
    $data['country'] = $jsonDecode->data->country;
    $data['province'] = $jsonDecode->data->region;
    $data['city'] = $jsonDecode->data->city;
    $data['isp'] = $jsonDecode->data->isp;
    return $data;
}
/**
 * 调用新浪地址库
 * */
function ip_sina($ip){
    $data = '';
    $urlSina = 'http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip='.$ip;
    $json = file_get_contents($urlSina);
    $jsonDecode = json_decode($json);
    if($jsonDecode == '-2'){
        $data['error'] = '未分配或者内网IP';
    }else{
        $data['country'] = $jsonDecode->country;
        $data['province'] = $jsonDecode->province;
        $data['city'] = $jsonDecode->city;
        $data['isp'] = $jsonDecode->isp;
        $data['district'] = $jsonDecode->district;
    }
    return $data;
}


